#pragma once
namespace html { namespace dom
{
  //////////////////////////////////////////////////////////////////////////
  // node
  //////////////////////////////////////////////////////////////////////////
  inline nodes node::operator() (const selector& _selector) { 
    nodes v; 
    _selector.select(*this,v); 
    return v; 
  }
  inline node node::add_comment (const std::string& _text) {
    // add new comment node
    operator+=(comment_node()); 
    // set the text after start tag to the given text which will be 
    // interpreted as comment
    children().back().text_after_start_tag() = _text;
    return *this;
  }
  //////////////////////////////////////////////////////////////////////////
  // node_data
  //////////////////////////////////////////////////////////////////////////
  inline void node_data::copy_from(const node_data& _node_data,node _parent)
  {
    // copy members
    tag_ = _node_data.tag_;
    id_ = _node_data.id_;
    classes_ = _node_data.classes_;
    attribs_ = _node_data.attribs_;
    text_after_start_tag_ = _node_data.text_after_start_tag_;
    text_after_end_tag_ = _node_data.text_after_end_tag_;
    // destroy existing children
    children_.clear();
    // clone all children
    for( nodes_data::const_iterator it=_node_data.children_.begin(); it!=_node_data.children_.end(); it++ )
    {
      // clone child from _node_data and put it into our children container
      children_.push_back(it->clone());
      // set the child's parent to _parent
      children_.back().set_parent(_parent);
    }
  }
} }
